﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using System.Windows.Threading;
using Yugi.Client.WebSerive;

namespace WpfApplication1
{
	/// <summary>
	/// Interaction logic for ListRoom.xaml
	/// </summary>
	public partial class ListRoom : UserControl
	{
        private DispatcherTimer on_out;
		public ListRoom()
		{
			this.InitializeComponent();
            this.Loaded += new RoutedEventHandler(ListRoom_Loaded);
		}

        void LoadData()
        {
        }
        public Room GetRoomRandom()
        {
            foreach (Room tmp in this.listView.Items)
            {
                if (((RoomInfo)tmp.DataContext).CountCreater > 0)
                {
                    return tmp;
                }
            }
            return null;
        }
        public void AddRoom(RoomInfo obj)
        {
            Room room = new Room();
            room.ID = (int)obj.RoomID;
            room.RoomName.Text = obj.RoomName;
            room.count.Text =obj.CountUser.ToString();
            room.DataContext = obj;
            room.level.Text = obj.Level.ToString();
            listView.Items.Add(room);
            room.OnClick += new Action<object>(room_OnClick);
        }
        void room_OnClick(object obj)
        {
            Room tb = obj as Room;
            if (tb == null) return;
            if (OnChoice != null)
                OnChoice(tb.DataContext);
        }
        void LoadNextData()
        {
            int d = 10;
            for (int i = 0; i < 4; i++)
            {
                Room room = new Room();
                listView.Items.Add(room);
                room.OnClick += new Action<object>(room_OnClick);
            }
        }
        void ListRoom_Loaded(object sender, RoutedEventArgs e)
        {
            LoadData();
        }
        public event Action<object> OnChoice;

        internal Room GetRoom(int roomid)
        {
            foreach (Room i in this.listView.Items)
            {
                if (i.ID == roomid)
                    return i;
            }
            return null;
        }
    }
}